Mealy machine